<template>
  <div class="list-container">
    <!-- 排序区域 -->
    <div class="sub-sort">
      <div class="sort">
        <!-- 使用数组遍历生成模板 -->
        <a
          href="javascript:;"
          v-for="(item, index) in sorTypeList"
          :key="index"
          @click="toggleSort(item.value)"
          :class="{ active: curSortType === item.value }"
        >{{ item.name }}排序</a>
      </div>
    </div>
    <!-- {{ keyWord }} -->
    <!-- 商品列表 -->
    <div class="sort-list-container">
      <goods-item v-for="good in goodList" :key="good.id" :goods="good" />
    </div>
    <XtxInfiniteLoad @load="loadNextList" :isFinished="isFinished" :isLoading="isLoading" />
  </div>
</template>

<script>

import goodsItem from '../Category/components/goods-item.vue'
import { useToggleSort } from './service/useToggleSort'
export default {
  name: 'SubSort',

  props: {
    keyWord: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  components: {
    goodsItem
  },
  setup (props) {
    const {
      sorTypeListRef,
      toggleSort,
      goodList,
      curSortTypeRef,
      isFinished,
      isLoading,
      loadNextList
    } = useToggleSort(props)
    return {
      sorTypeList: sorTypeListRef,
      curSortType: curSortTypeRef,
      toggleSort,
      goodList,
      isFinished,
      isLoading,
      loadNextList
    }
  }
}
</script>
<style scoped lang='less'>
.sort-list-container {
  display: flex;
  flex-wrap: wrap;
}
.sub-sort {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .sort {
    display: flex;
    a {
      height: 30px;
      line-height: 28px;
      border: 1px solid #e4e4e4;
      padding: 0 20px;
      margin-right: 20px;
      color: #999;
      border-radius: 2px;
      position: relative;
      transition: all 0.3s;
      &.active {
        background: @xtxColor;
        border-color: @xtxColor;
        color: #fff;
      }
      .arrow {
        position: absolute;
        border: 5px solid transparent;
        right: 8px;
        &.up {
          top: 3px;
          border-bottom-color: #bbb;
          &.active {
            border-bottom-color: @xtxColor;
          }
        }
        &.down {
          top: 15px;
          border-top-color: #bbb;
          &.active {
            border-top-color: @xtxColor;
          }
        }
      }
    }
  }
  .check {
    .xtx-checkbox {
      margin-left: 20px;
      color: #999;
    }
  }
}
.list-container {
  margin-top: 20px;
  padding: 0 20px;
  background: #fff;
}
</style>
